package xyz.supercode.tips;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class NodeController {

    @Autowired
    NodeService nodeService;
    @Autowired
    NodeRespostory nodeRespostory;

    @GetMapping("/node")
    public List<Node> findAll(Node node) {
        List<Node> list = new ArrayList<Node>();
        Iterable<Node> all = nodeRespostory.findAll();
        all.forEach(node1 -> {
            list.add(node1);
        });
        return list;
    }


    @GetMapping("/node/id/{id}")
    public Node findById(Node node) {
        return nodeService.findById(node.getId());
    }

    @PostMapping("/node")
    public Node save(Node node) {
        return nodeService.save(node);
    }


}